package com.FileDemo.Test;

/*
 *
 * */

import java.io.*;

public class CopyAviDemo {
    public static void main(String[] args) throws IOException {
        //记录开始时间
        long starttime = System.currentTimeMillis();

        //复制视频
//        method1();
//        method2();
//        method3();
        method4();

        //记录结束时间
        long endtime = System.currentTimeMillis();
        System.out.println("共耗时" + (endtime - starttime) + "毫秒");
    }

    //基本字节流一次读取一个字节             共耗时28665毫秒
    public static void method1() throws IOException {
        //桌面的录制视频  /Users/CT/Desktop/录制视频.mov
        //复制视频到     /Users/CT/Desktop/录制视频01.mov
        FileInputStream fis = new FileInputStream("/Users/CT/Desktop/录制视频.mov");
        FileOutputStream fos = new FileOutputStream("/Users/CT/Desktop/录制视频01.mov");

        int by;
        while ((by = fis.read()) != -1) {
            fos.write(by);
        }

        fis.close();
        fos.close();
    }

    ////基本字节流一次读取一个字节数组         共耗时144毫秒
    public static void method2() throws IOException {
        //桌面的录制视频  /Users/CT/Desktop/录制视频.mov
        //复制视频到     /Users/CT/Desktop/录制视频01.mov
        FileInputStream fis = new FileInputStream("/Users/CT/Desktop/录制视频.mov");
        FileOutputStream fos = new FileOutputStream("/Users/CT/Desktop/录制视频02.mov");

        byte[] bys = new byte[1024];
        int len;
        while ((len = fis.read(bys)) != -1) {
            fos.write(bys, 0, len);
        }

        fis.close();
        fos.close();
    }

    //字节缓冲流一次读取一个字节         共耗时176毫秒
    public static void method3() throws IOException {
        //桌面的录制视频  /Users/CT/Desktop/录制视频.mov
        //复制视频到     /Users/CT/Desktop/录制视频01.mov
        FileInputStream fis = new FileInputStream("/Users/CT/Desktop/录制视频.mov");
        FileOutputStream fos = new FileOutputStream("/Users/CT/Desktop/录制视频02.mov");
        BufferedInputStream bis = new BufferedInputStream(fis);
        BufferedOutputStream bos = new BufferedOutputStream(fos);

        int by;
        while ((by = bis.read()) != -1) {
            bos.write(by);
        }

        fis.close();
        fos.close();
    }

    //字节缓冲流一次读取一个字节数组
    public static void method4() throws IOException {
        //桌面的录制视频  /Users/CT/Desktop/录制视频.mov
        //复制视频到     /Users/CT/Desktop/录制视频01.mov
        FileInputStream fis = new FileInputStream("/Users/CT/Desktop/录制视频.mov");
        FileOutputStream fos = new FileOutputStream("/Users/CT/Desktop/录制视频03.mov");
        BufferedInputStream bis = new BufferedInputStream(fis);
        BufferedOutputStream bos = new BufferedOutputStream(fos);

        byte[] bys = new byte[1024];
        int len;
        while ((len = bis.read(bys)) != -1) {
            bos.write(bys, 0, len);
        }

        fis.close();
        fos.close();
    }
}
